import React, { useEffect, useState } from 'react'

export default function index() {
  useEffect(() => {
    // mounted
    return () => { 
      //  like beforDestroy
     }
  }, [])

  const [state, setState] = useState(0)
  useEffect(() => {
    return () => {
      console.log(state)
      // 点击两次 页面显示1 2 这里打印0 1
    }
  }, [state])
  const add = () => {
    setState(state => state + 1)
  }

  useEffect(() => {
    console.log("执行了")
  })
  return (
    <div>
      { state }
      <button onClick={add}>加一</button>
    </div>
  )
}
